<?php
class APICaller{
	
	function submit($method, $postParams = array(), $filePathParams = array(),  $debug = false){
		$params = array();
		$params['apiKey'] = 'APP001';
		$params['enc_req'] = $this->encode($postParams);
		
		
		if( $filePathParams ){
			foreach($filePathParams as $key=>$val){
				$params[$key] = '@'.$val;
			}
		}
		
		
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_URL, BASE.'api/'.$method);
		curl_setopt($ch, CURLOPT_POST, true);
		curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		$result = curl_exec($ch);
		
		$json = json_decode($result, true);
		
		if( is_null($json) ){
			echo('Resp: <pre>');
			print_r($result);
			echo('</pre>');
		}
		
		return $json;
	}
	/**
	* Method used for internal use to make encoded string for request
	* @param $params Array Item you would like to encode for API submittion
	* @return mixed                                       
	*/
	public function encode($params = array() ){
		return base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, API_SECRET, json_encode($params), MCRYPT_MODE_ECB));
	}
}
?>
